import 'package:flutter/material.dart';
import 'package:flutter_app/utils/http.dart';
import 'package:flutter_app/views/login.dart';
import 'package:flutter_app/widget/page_route_anim.dart';

class LeftPage extends StatefulWidget {
  @override
  _LeftPage createState() => _LeftPage();
}

class PageInfo {
  PageInfo(this.titleId, this.iconData, this.page, [this.withScaffold = true]);

  String titleId;
  IconData iconData;
  Widget page;
  bool withScaffold;
}


class _LeftPage extends State<LeftPage> {

  List<PageInfo> _pageInfo = new List();
  var userName = Container();
  var roleName = Container();

  @override
  void initState(){
    super.initState();

    // _pageInfo.add(PageInfo('测试', Icons.subject, LoginPage()));
    _pageInfo.add(PageInfo('退出登陆', Icons.exit_to_app, LoginPage()));
    getImage();
  }

  getImage() async{
    ResultData res = await HttpRequest.post('/webauth/jpush/getLoginUser', null, header:{'Content-Type':'application/json'});
    if(res.code == 0){

    }
    setState(() =>{
      userName = new Container(
        child: Text(
          res.data['userAcct'],
          style: TextStyle(color: Colors.white, fontSize: 12.0),
        )
      ),
      roleName = new Container(
          child: Text(
            res.data['roleName'],
            style: new TextStyle(
                color: Colors.white,
                fontSize: 16.0,
                fontWeight: FontWeight.bold),
          )
      )
  });
  }

  Widget build(BuildContext context) {
    return Scaffold(
      body:SafeArea(
        child: Column(
          children: [
            Container(
              height: 146.0,
              color: Theme.of(context).primaryColor,
              padding: EdgeInsets.only(top: 10, left: 10.0),
              child:Stack(
                children:[
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children:[
                      Container(
                        width: 64.0,
                        height: 64.0,
                        margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
                        decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          image: DecorationImage(
                            image: AssetImage('assets/images/app.png'),
                          ),
                        ),
                      ),
                      roleName,
                      userName
                    ]
                  ),
                  Align(
                    alignment: Alignment.topRight,
                    child: new IconButton(
                      iconSize: 18.0,
                      icon: new Icon(Icons.edit, color: Theme.of(context).primaryColor),
                      onPressed: () {}
                    ),
                  )
                ]
              )
            ),
            Container(
              height: 50.0,
              child: Material(
                color: Colors.grey[200],
                child: InkWell(
                  onTap: () {
                    print('点击');
                  },
                  child: Center(
                    child: Text(
                      "东软园区安防守护",
                      style: TextStyle(color: Theme.of(context).primaryColor, fontSize: 16.0),
                    ),
                  ),
                ),
              ),
            ),
            Expanded(
              child: new ListView.builder(
                padding: const EdgeInsets.all(0.0),
                itemCount: _pageInfo.length,
                itemBuilder: (BuildContext context, int index) {
                  PageInfo pageInfo = _pageInfo[index];
                  return new ListTile(
                    leading: new Icon(pageInfo.iconData),
                    title: Text(pageInfo.titleId),
                    onTap: () {
                      Navigator.of(context).push(FadeRouteBuilder(LoginPage()));
                    },
                  );
                }),
              flex: 1,
            )
          ],
        ),
      )
    );
  }
}
